<?php if(!defined('CALL')) exit('No direct script access allowed');

include_once('ctrl/page.class.php');
include_once('view/v_usercard.class.php');
include_once('view/v_menus.class.php');
include_once('view/v_messages.class.php');
include_once('models/m_user.class.php');
include_once('models/m_messages.class.php');

class PageMessages extends Page
{
	private $messages = null;
	
	public function __construct($actor, $user)
	{
		parent::__construct($actor, $user);
		$this->page_name = "plans";
		$this->prepare();
	}
	
	private function prepare()
	{
		$this->actor->load_messages($this->user->id);
	}
	
	protected function gen_main()
	{
		$html = '';
		
		Logger::Write(__FILE__." ".__FUNCTION__." line: ".__LINE__, '$actor->id=['.$actor->id.'] $user->id=['.$user->id.']');
		// если актор смотрит сам себя, то видит уведомления, о том что произошло
		if($this->actor->id == $this->user->id)
		{
			$html .= vMessages::build_systemMessageLine($this->actor->messages, $this->actor);
		}
		// иначе может переписываться с пользователем
		else
		{
			if($this->actor->messages == null) $this->actor->load_messages($this->user->id);
			$html .= vMessages::build_privateMessageLine($this->actor->messages, $this->actor, $this->user);
		}
		return $html;
	}

	protected function gen_side()
	{
		$html = '';
		
		$menus = new vMenus();
		$html .= $menus->gen_search_form();
		
		if($this->user->id)
		{
			if($this->user->id == $this->actor->id)
			{
				$html .= $menus->gen_message_menu($this->actor, $this->user);
			}
			else
			{
				$card = new vUsercard();
				$html .= $card->generate($this->user, $this->actor, TRUE);
			}
			$html .= $menus->gen_calendar_holder();
		}
		return $html;
	}

	protected function add_css()
	{
		return "";
	}

	protected function add_css_files()
	{
		return "";
	}

	protected function add_js()
	{
		
		return "";
	}

	protected function add_js_files()
	{
		return '<script type="text/javascript" src="'.ROOT_URL.'/js/EventProcessor.js"></script>';
	}
}
